package com.luocc.ccdemo.utils

import com.luocc.ccdemo.entity.Blog
import org.json.JSONArray
import org.json.JSONObject

/**
 * 解析json
 */
object ParseUtil {
    fun parseBlog(jsonArray: JSONArray): ArrayList<Blog> {
        val blogs = ArrayList<Blog>()
        for (i in 0 until jsonArray.length()) {
            val obj = jsonArray.get(i) as JSONObject
            val id = obj.getInt("id")
            val title = obj.getString("title")
            val sender = obj.getString("shareUser")
            val url = obj.getString("link")
            val time = obj.getString("niceShareDate")
            val blog = Blog(id, title, sender, url, time)
            blogs.add(blog)
        }
        return blogs
    }
}